/*******************************************************************************
 * copyright (c) 2009 - 2010 Simon Allen
 *
 * This file is part of Convex Media Converter.
 *
 * Convex Media Converter is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * Convex Media Converter is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with Convex Media Converter; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 ******************************************************************************/

#include "outputsettings.h"

#include <string>

#include <QFile>

using namespace std;


const QString OutputSettings::FORMAT_AUDIO("audio");
const QString OutputSettings::FORMAT_MPEGTS("mpeg-ts");
const QString OutputSettings::FORMAT_MPEGPS("mpeg-ps");
const QString OutputSettings::FORMAT_MPEG1("mpeg-1");
const QString OutputSettings::FORMAT_OGV("ogv");
const QString OutputSettings::FORMAT_WMV("wmv");
const QString OutputSettings::FORMAT_DVD("dvd");
const QString OutputSettings::FORMAT_MJPEG("mjpeg");
const QString OutputSettings::FORMAT_MKV("mkv");
const QString OutputSettings::FORMAT_RAW("raw");
const QString OutputSettings::FORMAT_MPEG4("mp4");
const QString OutputSettings::FORMAT_FLASH("flash");
const QString OutputSettings::FORMAT_AVI("avi");

const QString OutputSettings::FORMAT_AUDIO_DESC("Audio Only");
const QString OutputSettings::FORMAT_MPEGTS_DESC("MPEG-TS");
const QString OutputSettings::FORMAT_MPEGPS_DESC("MPEG-PS");
const QString OutputSettings::FORMAT_MPEG1_DESC("MPEG-1");
const QString OutputSettings::FORMAT_OGV_DESC("Ogv/Ogg");
const QString OutputSettings::FORMAT_WMV_DESC("ASF/WMV");
const QString OutputSettings::FORMAT_DVD_DESC("DVD");
const QString OutputSettings::FORMAT_MJPEG_DESC("MJPEG");
const QString OutputSettings::FORMAT_MKV_DESC("MKV");
const QString OutputSettings::FORMAT_RAW_DESC("RAW");
const QString OutputSettings::FORMAT_MPEG4_DESC("MP4/MOV");
const QString OutputSettings::FORMAT_FLASH_DESC("Flash Video");
const QString OutputSettings::FORMAT_AVI_DESC("AVI");

const QString OutputSettings::AUDIO_CODEC_MP2("mp2");
const QString OutputSettings::AUDIO_CODEC_MP3("libmp3lame");
const QString OutputSettings::AUDIO_CODEC_AAC("libfaac");
const QString OutputSettings::AUDIO_CODEC_AC3("ac3");
const QString OutputSettings::AUDIO_CODEC_VORBIS("libvorbis");
const QString OutputSettings::AUDIO_CODEC_FLAC("flac");
const QString OutputSettings::AUDIO_CODEC_WAV("pcm_u8");
const QString OutputSettings::AUDIO_CODEC_WMAV1("wmav1");
const QString OutputSettings::AUDIO_CODEC_WMAV2("wmav2");

const QString OutputSettings::AUDIO_CODEC_MP2_DESC("MPEG-1 Layer 2 (MP2)");
const QString OutputSettings::AUDIO_CODEC_MP3_DESC("MPEG-1 Layer 3 (MP3)");
const QString OutputSettings::AUDIO_CODEC_AAC_DESC("MPEG-4 Audio (M4A/AAC)");
const QString OutputSettings::AUDIO_CODEC_AC3_DESC("A52/AC-3");
const QString OutputSettings::AUDIO_CODEC_VORBIS_DESC("Vorbis");
const QString OutputSettings::AUDIO_CODEC_FLAC_DESC("Flac");
const QString OutputSettings::AUDIO_CODEC_WAV_DESC("WAV");
const QString OutputSettings::AUDIO_CODEC_WMAV1_DESC("WMA");
const QString OutputSettings::AUDIO_CODEC_WMAV2_DESC("WMA2");

const QString OutputSettings::VIDEO_CODEC_MPEG1("mpeg1video");
const QString OutputSettings::VIDEO_CODEC_MPEG2("mpeg2video");
const QString OutputSettings::VIDEO_CODEC_XVID("libxvid");
const QString OutputSettings::VIDEO_CODEC_H264("libx264");
const QString OutputSettings::VIDEO_CODEC_H263("h263p");
const QString OutputSettings::VIDEO_CODEC_WMV1("wmv1");
const QString OutputSettings::VIDEO_CODEC_WMV2("wmv2");
const QString OutputSettings::VIDEO_CODEC_MJPEG("mjpeg");
const QString OutputSettings::VIDEO_CODEC_THEORA("libtheora");
const QString OutputSettings::VIDEO_CODEC_DIRAC("libdirac");

const QString OutputSettings::VIDEO_CODEC_MPEG1_DESC("MPEG-1");
const QString OutputSettings::VIDEO_CODEC_MPEG2_DESC("MPEG-2");
const QString OutputSettings::VIDEO_CODEC_XVID_DESC("Xvid (MPEG-4 part 2)");
const QString OutputSettings::VIDEO_CODEC_H264_DESC("H.264 (MPEG-4 part 10)");
const QString OutputSettings::VIDEO_CODEC_H263_DESC("H.263");
const QString OutputSettings::VIDEO_CODEC_WMV1_DESC("WMV1");
const QString OutputSettings::VIDEO_CODEC_WMV2_DESC("WMV2");
const QString OutputSettings::VIDEO_CODEC_MJPEG_DESC("M-JPEG");
const QString OutputSettings::VIDEO_CODEC_THEORA_DESC("Theora");
const QString OutputSettings::VIDEO_CODEC_DIRAC_DESC("Dirac");

const QString OutputSettings::AUDIO_BITRATE_VERY_LOW("64");
const QString OutputSettings::AUDIO_BITRATE_LOW("96");
const QString OutputSettings::AUDIO_BITRATE_NORMAL("128");
const QString OutputSettings::AUDIO_BITRATE_HIGH("192");
const QString OutputSettings::AUDIO_BITRATE_VERY_HIGH("256");
const QString OutputSettings::AUDIO_BITRATE_ULTRA_HIGH("320");

const QString OutputSettings::AUDIO_BITRATE_VERY_LOW_DESC("Very Low (64 kbps)");
const QString OutputSettings::AUDIO_BITRATE_LOW_DESC("Low (96 kbps)");
const QString OutputSettings::AUDIO_BITRATE_NORMAL_DESC("Normal (128 kbps)");
const QString OutputSettings::AUDIO_BITRATE_HIGH_DESC("High (192 kbps)");
const QString OutputSettings::AUDIO_BITRATE_VERY_HIGH_DESC("Very High (256 kbps)");
const QString OutputSettings::AUDIO_BITRATE_ULTRA_HIGH_DESC("Ultra High (320 kbps)");

const int OutputSettings::AUDIO_MP3_VBR_LOW = 9;
const int OutputSettings::AUDIO_MP3_VBR_NORMAL = 5;
const int OutputSettings::AUDIO_MP3_VBR_HIGH = 2;
const int OutputSettings::AUDIO_MP3_VBR_VERY_HIGH = 0;

const int OutputSettings::AUDIO_VORBIS_VBR_VERY_LOW = 0;
const int OutputSettings::AUDIO_VORBIS_VBR_LOW = 2;
const int OutputSettings::AUDIO_VORBIS_VBR_NORMAL = 4;
const int OutputSettings::AUDIO_VORBIS_VBR_HIGH = 6;
const int OutputSettings::AUDIO_VORBIS_VBR_VERY_HIGH = 8;
const int OutputSettings::AUDIO_VORBIS_VBR_ULTRA_HIGH = 9;

const int OutputSettings::AUDIO_AAC_VBR_VERY_LOW = 60;
const int OutputSettings::AUDIO_AAC_VBR_LOW = 90;
const int OutputSettings::AUDIO_AAC_VBR_NORMAL = 120;
const int OutputSettings::AUDIO_AAC_VBR_HIGH = 240;
const int OutputSettings::AUDIO_AAC_VBR_VERY_HIGH = 500;

const QString OutputSettings::AUDIO_MODE_VBR("vbr");
const QString OutputSettings::AUDIO_MODE_ABR("abr");
const QString OutputSettings::AUDIO_MODE_CBR("cbr");

const QString OutputSettings::AUDIO_MODE_VBR_DESC("Variable (VBR) - Best");
const QString OutputSettings::AUDIO_MODE_ABR_DESC("Average (ABR)");
const QString OutputSettings::AUDIO_MODE_CBR_DESC("Constant (CBR)");

const QString OutputSettings::AUDIO_CHANNELS_1("1");
const QString OutputSettings::AUDIO_CHANNELS_2("2");
const QString OutputSettings::AUDIO_CHANNELS_4("4");
const QString OutputSettings::AUDIO_CHANNELS_2_1("3");
const QString OutputSettings::AUDIO_CHANNELS_4_1("5");
const QString OutputSettings::AUDIO_CHANNELS_5_1("6");
const QString OutputSettings::AUDIO_CHANNELS_6_1("7");
const QString OutputSettings::AUDIO_CHANNELS_7_1("8");

const QString OutputSettings::AUDIO_CHANNELS_1_DESC("Mono");
const QString OutputSettings::AUDIO_CHANNELS_2_DESC("Stereo");
const QString OutputSettings::AUDIO_CHANNELS_4_DESC("Quadraphonic");
const QString OutputSettings::AUDIO_CHANNELS_2_1_DESC("2.1");
const QString OutputSettings::AUDIO_CHANNELS_4_1_DESC("4.1 (Surround)");
const QString OutputSettings::AUDIO_CHANNELS_5_1_DESC("5.1 (Surround)");
const QString OutputSettings::AUDIO_CHANNELS_6_1_DESC("6.1 (Surround)");
const QString OutputSettings::AUDIO_CHANNELS_7_1_DESC("7.1 (Surround)");

const QString OutputSettings::VIDEO_STANDARD_576P("576p");
const QString OutputSettings::VIDEO_STANDARD_480P("480p");
const QString OutputSettings::VIDEO_STANDARD_720P("720p");
const QString OutputSettings::VIDEO_STANDARD_1080P("1080p");
const QString OutputSettings::VIDEO_STANDARD_QVGA("qvga");
const QString OutputSettings::VIDEO_STANDARD_VGA("vga");
const QString OutputSettings::VIDEO_STANDARD_SVGA("svga");
const QString OutputSettings::VIDEO_STANDARD_XGA("xga");
const QString OutputSettings::VIDEO_STANDARD_CUSTOM("custom");

const QString OutputSettings::VIDEO_STANDARD_576P_DESC("576p (PAL DV/DVD)");
const QString OutputSettings::VIDEO_STANDARD_480P_DESC("480p (NTSC DV/DVD)");
const QString OutputSettings::VIDEO_STANDARD_720P_DESC("720p HD");
const QString OutputSettings::VIDEO_STANDARD_1080P_DESC("1080p HD");
const QString OutputSettings::VIDEO_STANDARD_QVGA_DESC("QVGA (320x240)");
const QString OutputSettings::VIDEO_STANDARD_VGA_DESC("VGA (640x480)");
const QString OutputSettings::VIDEO_STANDARD_SVGA_DESC("SVGA (800x600)");
const QString OutputSettings::VIDEO_STANDARD_XGA_DESC("XGA (1024x768)");
const QString OutputSettings::VIDEO_STANDARD_CUSTOM_DESC("Custom");

const QString OutputSettings::VIDEO_ASPECT_FULLSCREEN("4:3");
const QString OutputSettings::VIDEO_ASPECT_WIDESCREEN("16:9");

const QString OutputSettings::VIDEO_ASPECT_FULLSCREEN_DESC("4:3 (Fullscreen)");
const QString OutputSettings::VIDEO_ASPECT_WIDESCREEN_DESC("16:9 (Widescreen)");

const QString OutputSettings::EXTENSION_TS(".ts");
const QString OutputSettings::EXTENSION_MPG(".mpg");
const QString OutputSettings::EXTENSION_OGG(".ogg");
const QString OutputSettings::EXTENSION_WMV(".wmv");
const QString OutputSettings::EXTENSION_MJP(".mjp");
const QString OutputSettings::EXTENSION_MKV(".mkv");
const QString OutputSettings::EXTENSION_RAW(".raw");
const QString OutputSettings::EXTENSION_MP4(".mp4");
const QString OutputSettings::EXTENSION_FLV(".flv");
const QString OutputSettings::EXTENSION_AVI(".avi");

const QString OutputSettings::EXTENSION_AUDIO_MP2(".mp2");
const QString OutputSettings::EXTENSION_AUDIO_MP3(".mp3");
const QString OutputSettings::EXTENSION_AUDIO_M4A(".m4a");
const QString OutputSettings::EXTENSION_AUDIO_AC3(".ac3");
const QString OutputSettings::EXTENSION_AUDIO_OGG(".ogg");
const QString OutputSettings::EXTENSION_AUDIO_FLAC(".flac");
const QString OutputSettings::EXTENSION_AUDIO_WAV(".wav");
const QString OutputSettings::EXTENSION_AUDIO_WMA(".wma");

const QStringList OutputSettings::MP2_SAMPLE_RATES(QStringList() << "32000" << "44100" << "48000");
const QStringList OutputSettings::MP3_SAMPLE_RATES(QStringList() << "32000" << "44100" << "48000");
const QStringList OutputSettings::AAC_SAMPLE_RATES(QStringList() << "32000" << "44100" << "48000"
						   << "64000" << "96000");
const QStringList OutputSettings::AC3_SAMPLE_RATES(QStringList() << "32000" << "44100" << "48000");
const QStringList OutputSettings::VORBIS_SAMPLE_RATES(QStringList() << "8000" << "11025" << "12000"
						      << "16000" << "22050" << "24000"
						      << "32000" << "44100" << "48000" << "64000"
						      << "96000" << "128000" << "192000");
const QStringList OutputSettings::FLAC_SAMPLE_RATES(QStringList() << "32000" << "44100" << "48000"
						    << "96000" << "128000" << "256000" << "512000"
						    << "655350");
const QStringList OutputSettings::WAV_SAMPLE_RATES(QStringList() << "8000" << "11025" << "12000"
						   << "16000" << "22050" << "24000"
						   << "32000" << "44100" << "48000");
const QStringList OutputSettings::WMAV1_SAMPLE_RATES(QStringList() << "32000" << "44100" << "48000");
const QStringList OutputSettings::WMAV2_SAMPLE_RATES(QStringList() << "32000" << "44100" << "48000");

const QString PresetSettings::KEY_FORMAT("format");
const QString PresetSettings::KEY_AUDIO_STREAM("audioStream");
const QString PresetSettings::KEY_VIDEO_STREAM("videoStream");
const QString PresetSettings::KEY_CODEC("codec");
const QString PresetSettings::KEY_BITRATE("bitrate");
const QString PresetSettings::KEY_MODE("mode");
const QString PresetSettings::KEY_SAMPLE_RATE("sampleRate");
const QString PresetSettings::KEY_CHANNELS("channels");
const QString PresetSettings::KEY_STANDARD("standard");
const QString PresetSettings::KEY_WIDTH("width");
const QString PresetSettings::KEY_HEIGHT("height");
const QString PresetSettings::KEY_ASPECT("aspect");
const QString PresetSettings::KEY_FRAME_RATE("frameRate");
const QString PresetSettings::KEY_EXTENSION("extension");
const QString PresetSettings::KEY_CMD_OPTIONS("cmdOptions");

OutputSettings::OutputSettings()
{
	audio = false;
	audioBitrate = -1;
	audioSampleRate = -1;
	audioChannels = -1;
	video = false;
	videoBitrate = -1;
	width = -1;
	height = -1;
	frameRate = -1;
}

PresetSettings::PresetSettings(const QSettings::Scope scope, const QString &organization,
			       const QString &application, QObject *parent):
			       QSettings(scope, organization, application, parent)
{
	createFormatPairs();
	createAudioCodecPairs();
	createVideoCodecPairs();
	createAudioBitratePairs();
	createAudioModePairs();
	createAudioChannelsPairs();
	createVideoStandardPairs();
	createVideoAspectPairs();

	if (!QFile::exists(fileName()))
		writeDefaultPresets();
}

void PresetSettings::createFormatPairs()
{
	formatPairs.push_back(QPair<QString, QString>(OutputSettings::FORMAT_AUDIO, OutputSettings::FORMAT_AUDIO_DESC));
	formatPairs.push_back(QPair<QString, QString>(OutputSettings::FORMAT_MPEGTS, OutputSettings::FORMAT_MPEGTS_DESC));
	formatPairs.push_back(QPair<QString, QString>(OutputSettings::FORMAT_MPEGPS, OutputSettings::FORMAT_MPEGPS_DESC));
	formatPairs.push_back(QPair<QString, QString>(OutputSettings::FORMAT_MPEG1, OutputSettings::FORMAT_MPEG1_DESC));
	formatPairs.push_back(QPair<QString, QString>(OutputSettings::FORMAT_OGV, OutputSettings::FORMAT_OGV_DESC));
	formatPairs.push_back(QPair<QString, QString>(OutputSettings::FORMAT_WMV, OutputSettings::FORMAT_WMV_DESC));
	formatPairs.push_back(QPair<QString, QString>(OutputSettings::FORMAT_DVD, OutputSettings::FORMAT_DVD_DESC));
	formatPairs.push_back(QPair<QString, QString>(OutputSettings::FORMAT_MJPEG, OutputSettings::FORMAT_MJPEG_DESC));
	formatPairs.push_back(QPair<QString, QString>(OutputSettings::FORMAT_MKV, OutputSettings::FORMAT_MKV_DESC));
	formatPairs.push_back(QPair<QString, QString>(OutputSettings::FORMAT_RAW, OutputSettings::FORMAT_RAW_DESC));
	formatPairs.push_back(QPair<QString, QString>(OutputSettings::FORMAT_MPEG4, OutputSettings::FORMAT_MPEG4_DESC));
	formatPairs.push_back(QPair<QString, QString>(OutputSettings::FORMAT_FLASH, OutputSettings::FORMAT_FLASH_DESC));
	formatPairs.push_back(QPair<QString, QString>(OutputSettings::FORMAT_AVI, OutputSettings::FORMAT_AVI_DESC));
}

void PresetSettings::createAudioCodecPairs()
{
	audioCodecPairs.push_back(QPair<QString, QString>(OutputSettings::AUDIO_CODEC_MP2, OutputSettings::AUDIO_CODEC_MP2_DESC));
	audioCodecPairs.push_back(QPair<QString, QString>(OutputSettings::AUDIO_CODEC_MP3, OutputSettings::AUDIO_CODEC_MP3_DESC));
	audioCodecPairs.push_back(QPair<QString, QString>(OutputSettings::AUDIO_CODEC_AAC, OutputSettings::AUDIO_CODEC_AAC_DESC));
	audioCodecPairs.push_back(QPair<QString, QString>(OutputSettings::AUDIO_CODEC_AC3, OutputSettings::AUDIO_CODEC_AC3_DESC));
	audioCodecPairs.push_back(QPair<QString, QString>(OutputSettings::AUDIO_CODEC_VORBIS, OutputSettings::AUDIO_CODEC_VORBIS_DESC));
	audioCodecPairs.push_back(QPair<QString, QString>(OutputSettings::AUDIO_CODEC_FLAC, OutputSettings::AUDIO_CODEC_FLAC_DESC));
	audioCodecPairs.push_back(QPair<QString, QString>(OutputSettings::AUDIO_CODEC_WAV, OutputSettings::AUDIO_CODEC_WAV_DESC));
	audioCodecPairs.push_back(QPair<QString, QString>(OutputSettings::AUDIO_CODEC_WMAV1, OutputSettings::AUDIO_CODEC_WMAV1_DESC));
	audioCodecPairs.push_back(QPair<QString, QString>(OutputSettings::AUDIO_CODEC_WMAV2, OutputSettings::AUDIO_CODEC_WMAV2_DESC));
}

void PresetSettings::createVideoCodecPairs()
{
	videoCodecPairs.push_back(QPair<QString, QString>(OutputSettings::VIDEO_CODEC_MPEG1, OutputSettings::VIDEO_CODEC_MPEG1_DESC));
	videoCodecPairs.push_back(QPair<QString, QString>(OutputSettings::VIDEO_CODEC_MPEG2, OutputSettings::VIDEO_CODEC_MPEG2_DESC));
	videoCodecPairs.push_back(QPair<QString, QString>(OutputSettings::VIDEO_CODEC_XVID, OutputSettings::VIDEO_CODEC_XVID_DESC));
	videoCodecPairs.push_back(QPair<QString, QString>(OutputSettings::VIDEO_CODEC_H264, OutputSettings::VIDEO_CODEC_H264_DESC));
	videoCodecPairs.push_back(QPair<QString, QString>(OutputSettings::VIDEO_CODEC_H263, OutputSettings::VIDEO_CODEC_H263_DESC));
	videoCodecPairs.push_back(QPair<QString, QString>(OutputSettings::VIDEO_CODEC_WMV1, OutputSettings::VIDEO_CODEC_WMV1_DESC));
	videoCodecPairs.push_back(QPair<QString, QString>(OutputSettings::VIDEO_CODEC_WMV2, OutputSettings::VIDEO_CODEC_WMV2_DESC));
	videoCodecPairs.push_back(QPair<QString, QString>(OutputSettings::VIDEO_CODEC_MJPEG, OutputSettings::VIDEO_CODEC_MJPEG_DESC));
	videoCodecPairs.push_back(QPair<QString, QString>(OutputSettings::VIDEO_CODEC_THEORA, OutputSettings::VIDEO_CODEC_THEORA_DESC));
	videoCodecPairs.push_back(QPair<QString, QString>(OutputSettings::VIDEO_CODEC_DIRAC, OutputSettings::VIDEO_CODEC_DIRAC_DESC));
}

void PresetSettings::createAudioBitratePairs()
{
	audioBitratePairs.push_back(QPair<QString, QString>(OutputSettings::AUDIO_BITRATE_VERY_LOW, OutputSettings::AUDIO_BITRATE_VERY_LOW_DESC));
	audioBitratePairs.push_back(QPair<QString, QString>(OutputSettings::AUDIO_BITRATE_LOW, OutputSettings::AUDIO_BITRATE_LOW_DESC));
	audioBitratePairs.push_back(QPair<QString, QString>(OutputSettings::AUDIO_BITRATE_NORMAL, OutputSettings::AUDIO_BITRATE_NORMAL_DESC));
	audioBitratePairs.push_back(QPair<QString, QString>(OutputSettings::AUDIO_BITRATE_HIGH, OutputSettings::AUDIO_BITRATE_HIGH_DESC));
	audioBitratePairs.push_back(QPair<QString, QString>(OutputSettings::AUDIO_BITRATE_VERY_HIGH, OutputSettings::AUDIO_BITRATE_VERY_HIGH_DESC));
	audioBitratePairs.push_back(QPair<QString, QString>(OutputSettings::AUDIO_BITRATE_ULTRA_HIGH, OutputSettings::AUDIO_BITRATE_ULTRA_HIGH_DESC));
}

void PresetSettings::createAudioModePairs()
{
	audioModePairs.push_back(QPair<QString, QString>(OutputSettings::AUDIO_MODE_VBR, OutputSettings::AUDIO_MODE_VBR_DESC));
	audioModePairs.push_back(QPair<QString, QString>(OutputSettings::AUDIO_MODE_ABR, OutputSettings::AUDIO_MODE_ABR_DESC));
	audioModePairs.push_back(QPair<QString, QString>(OutputSettings::AUDIO_MODE_CBR, OutputSettings::AUDIO_MODE_CBR_DESC));
}

void PresetSettings::createAudioChannelsPairs()
{
	audioChannelPairs.push_back(QPair<QString, QString>(OutputSettings::AUDIO_CHANNELS_1, OutputSettings::AUDIO_CHANNELS_1_DESC));
	audioChannelPairs.push_back(QPair<QString, QString>(OutputSettings::AUDIO_CHANNELS_2, OutputSettings::AUDIO_CHANNELS_2_DESC));
	audioChannelPairs.push_back(QPair<QString, QString>(OutputSettings::AUDIO_CHANNELS_4, OutputSettings::AUDIO_CHANNELS_4_DESC));
	audioChannelPairs.push_back(QPair<QString, QString>(OutputSettings::AUDIO_CHANNELS_2_1, OutputSettings::AUDIO_CHANNELS_2_1_DESC));
	audioChannelPairs.push_back(QPair<QString, QString>(OutputSettings::AUDIO_CHANNELS_4_1, OutputSettings::AUDIO_CHANNELS_4_1_DESC));
	audioChannelPairs.push_back(QPair<QString, QString>(OutputSettings::AUDIO_CHANNELS_5_1, OutputSettings::AUDIO_CHANNELS_5_1_DESC));
	audioChannelPairs.push_back(QPair<QString, QString>(OutputSettings::AUDIO_CHANNELS_6_1, OutputSettings::AUDIO_CHANNELS_6_1_DESC));
	audioChannelPairs.push_back(QPair<QString, QString>(OutputSettings::AUDIO_CHANNELS_7_1, OutputSettings::AUDIO_CHANNELS_7_1_DESC));
}

void PresetSettings::createVideoStandardPairs()
{
	videoStandardPairs.push_back(QPair<QString, QString>(OutputSettings::VIDEO_STANDARD_576P, OutputSettings::VIDEO_STANDARD_576P_DESC));
	videoStandardPairs.push_back(QPair<QString, QString>(OutputSettings::VIDEO_STANDARD_480P, OutputSettings::VIDEO_STANDARD_480P_DESC));
	videoStandardPairs.push_back(QPair<QString, QString>(OutputSettings::VIDEO_STANDARD_720P, OutputSettings::VIDEO_STANDARD_720P_DESC));
	videoStandardPairs.push_back(QPair<QString, QString>(OutputSettings::VIDEO_STANDARD_1080P, OutputSettings::VIDEO_STANDARD_1080P_DESC));
	videoStandardPairs.push_back(QPair<QString, QString>(OutputSettings::VIDEO_STANDARD_QVGA, OutputSettings::VIDEO_STANDARD_QVGA_DESC));
	videoStandardPairs.push_back(QPair<QString, QString>(OutputSettings::VIDEO_STANDARD_VGA, OutputSettings::VIDEO_STANDARD_VGA_DESC));
	videoStandardPairs.push_back(QPair<QString, QString>(OutputSettings::VIDEO_STANDARD_SVGA, OutputSettings::VIDEO_STANDARD_SVGA_DESC));
	videoStandardPairs.push_back(QPair<QString, QString>(OutputSettings::VIDEO_STANDARD_XGA, OutputSettings::VIDEO_STANDARD_XGA_DESC));
	videoStandardPairs.push_back(QPair<QString, QString>(OutputSettings::VIDEO_STANDARD_CUSTOM, OutputSettings::VIDEO_STANDARD_CUSTOM_DESC));
}

void PresetSettings::createVideoAspectPairs()
{
	videoAspectPairs.push_back(QPair<QString, QString>(OutputSettings::VIDEO_ASPECT_FULLSCREEN, OutputSettings::VIDEO_ASPECT_FULLSCREEN_DESC));
	videoAspectPairs.push_back(QPair<QString, QString>(OutputSettings::VIDEO_ASPECT_WIDESCREEN, OutputSettings::VIDEO_ASPECT_WIDESCREEN_DESC));
}

void PresetSettings::writeDefaultPresets()
{

}

QString PresetSettings::getMatch(const QString key, const PAIR_TYPE type) const
{
	switch (type)
	{
		case FORMAT:
			for (QList<QPair<QString, QString> >::const_iterator iter = formatPairs.begin();
			     iter != formatPairs.end(); iter++)
			{
				if (iter->first == key)
					return iter->second;

				if (iter->second == key)
					return iter->first;
			}

			break;

		case AUDIO_CODEC:
			for (QList<QPair<QString, QString> >::const_iterator iter = audioCodecPairs.begin();
			     iter != audioCodecPairs.end(); iter++)
			{
				if (iter->first == key)
					return iter->second;

				if (iter->second == key)
					return iter->first;
			}

			break;

		case VIDEO_CODEC:
			for (QList<QPair<QString, QString> >::const_iterator iter = videoCodecPairs.begin();
			     iter != videoCodecPairs.end(); iter++)
			{
				if (iter->first == key)
					return iter->second;

				if (iter->second == key)
					return iter->first;
			}

			break;

		case AUDIO_BITRATE:
			for (QList<QPair<QString, QString> >::const_iterator iter = audioBitratePairs.begin();
			     iter != audioBitratePairs.end(); iter++)
			{
				if (iter->first == key)
					return iter->second;

				if (iter->second == key)
					return iter->first;
			}

			break;

		case AUDIO_MODE:
			for (QList<QPair<QString, QString> >::const_iterator iter = audioModePairs.begin();
			     iter != audioModePairs.end(); iter++)
			{
				if (iter->first == key)
					return iter->second;

				if (iter->second == key)
					return iter->first;
			}

			break;

		case AUDIO_CHANNELS:
			for (QList<QPair<QString, QString> >::const_iterator iter = audioChannelPairs.begin();
			     iter != audioChannelPairs.end(); iter++)
			{
				if (iter->first == key)
					return iter->second;

				if (iter->second == key)
					return iter->first;
			}

			break;

		case VIDEO_STANDARD:
			for (QList<QPair<QString, QString> >::const_iterator iter = videoStandardPairs.begin();
			     iter != videoStandardPairs.end(); iter++)
			{
				if (iter->first == key)
					return iter->second;

				if (iter->second == key)
					return iter->first;
			}

		default:
			for (QList<QPair<QString, QString> >::const_iterator iter = videoAspectPairs.begin();
			     iter != videoAspectPairs.end(); iter++)
			{
				if (iter->first == key)
					return iter->second;

				if (iter->second == key)
					return iter->first;
			}
	}

	return QString();
}

QList<QPair<QString, QString> > PresetSettings::getPairs(const PAIR_TYPE type) const
{
	switch (type)
	{
		case FORMAT:
			return formatPairs;

		case AUDIO_CODEC:
			return audioCodecPairs;

		case VIDEO_CODEC:
			return videoCodecPairs;

		case AUDIO_BITRATE:
			return audioBitratePairs;

		case AUDIO_MODE:
			return audioModePairs;

		case AUDIO_CHANNELS:
			return audioChannelPairs;

		default:
			return videoStandardPairs;
	}
}
